import cv2
from utils.img_utils import *

cat = cv2.imread('./img/cat.jpg', cv2.IMREAD_GRAYSCALE)

# 超过阈值的部分去maxval(最大值), 否则取0
# 二值处理 超过127的设置为255, 没有超过127的设置为0
ret, thresh1 = cv2.threshold(cat, 127, 255, cv2.THRESH_BINARY)
cv_show('BINARY', thresh1)
# THRESH_BINARY 的反转
ret, thresh2 = cv2.threshold(cat, 127, 255, cv2.THRESH_BINARY_INV)
cv_show('BINARY', thresh2)

# 大于阈值的部分设为阈值, 否则不变
# 大于127的设置为127, 其他的不变
ret, thresh3 = cv2.threshold(cat, 127, 255, cv2.THRESH_TRUNC)
cv_show('TRUNC', thresh3)

# 大于阈值部分不改变, 否则设为0
# 大于127的部分不变, 其他的设置为0
ret, thresh4 = cv2.threshold(cat, 127, 255, cv2.THRESH_TOZERO)
cv_show(thresh4)

# THRESH_TOZERO的反转
ret, thresh5 = cv2.threshold(cat, 127, 255, cv2.THRESH_TOZERO_INV)
